﻿using Dynamics.NAV.Metro.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace Dynamics.NAV.Metro.Common
{
    public class VariableSizedGridView : GridView
    {
        private int rowVal;
        private int colVal;
        private Random _rand;

        public VariableSizedGridView()
        {
            _rand = new Random();
        }

        protected override void PrepareContainerForItemOverride(Windows.UI.Xaml.DependencyObject element, object item)
        {
            base.PrepareContainerForItemOverride(element, item);
            HomeItem dataItem = item as HomeItem;
            int index = -1;

            if (dataItem != null)
            {
                index = dataItem.Group.Items.IndexOf(dataItem);
            }

            if (index >= 0 && index < dataItem.Group.Sequence.Count)
            {

                colVal = (int)dataItem.Group.Sequence[index].Width;
                rowVal = (int)dataItem.Group.Sequence[index].Height;

            }
            else
            {
                colVal = (int)LayoutSizes.OtherSmallItem.Width;
                rowVal = (int)LayoutSizes.OtherSmallItem.Height;

            }


            VariableSizedWrapGrid.SetRowSpan(element as UIElement, rowVal);
            VariableSizedWrapGrid.SetColumnSpan(element as UIElement, colVal);
        }
    }

    public static class LayoutSizes
    {
        public static Size PrimaryItem = new Size(6, 2);
        public static Size SecondarySmallItem = new Size(3, 1);
        public static Size SecondaryTallItem = new Size(3, 2);
        public static Size OtherSmallItem = new Size(2, 1);

    }
}
